package com.huaxiafinance.management.controller;

import com.huaxiafinance.management.dto.request.QueryFranchiseeToBeInfoDto;
import com.huaxiafinance.management.mapper.FrontSendMessageMapper;
import com.huaxiafinance.management.model.FrontSendMessage;
import com.huaxiafinance.management.util.MessageResult;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 查询发送的短信验证码记录
 *
 * @author yangtong
 * @create 2018-01-12 13:52
 **/
@Controller
@RequestMapping("/frontSendMessage")
public class FrontSendMessageController {
    private static final Logger log = Logger.getLogger(FrontSendMessageController.class);
    @Autowired
    private FrontSendMessageMapper frontSendMessageMapper;

    @RequestMapping(value = "/querySendMessage", produces = "application/json;charset=utf-8")
    @ResponseBody
    public String sendMessage(QueryFranchiseeToBeInfoDto dto) {
        log.info("接收到的请求参数为----------------------:" + dto);
        MessageResult result = new MessageResult();
        dto.setPage(dto.getPage() == null ? null : (dto.getPage() - 1) * dto.getRows());
        String start = dto.getStart();
        String end = dto.getEnd();
        if (start == null || "".equalsIgnoreCase(start) || end == null || "".equalsIgnoreCase(end)) {
            dto.setStart(null);
            dto.setEnd(null);
        }
        Integer count = frontSendMessageMapper.selectByParamCount(dto);
        List<FrontSendMessage> messageList = frontSendMessageMapper.selectByParam(dto);
        Map map = new HashMap<>();
        map.put("messaegList", messageList);
        result.setData(map);
        result.setRows(count);
        result.setSuccessResult();
        return result.getAsJSON();
    }
}
